﻿#define _CRT_SECURE_NO_WARNINGS
#include"test.h"
typedef int BTDataType;
// ⼆叉链
typedef struct BinaryTreeNode
{
	struct BinTreeNode* left; // 指向当前结点左孩⼦
	struct BinTreeNode* right; // 指向当前结点右孩⼦
	BTDataType val; // 当前结点值域
}BTNode;
BTNode* BuyBTNode(int val)
{
	BTNode* newnode = (BTNode*)malloc(sizeof(BTNode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		return NULL;
	} 
	newnode->val = val;
	newnode->left = NULL;
	newnode->right = NULL;
	return newnode;
} 
BTNode* CreateTree()
{
	BTNode* n1 = BuyBTNode(1);
	BTNode* n2 = BuyBTNode(2);
	BTNode* n3 = BuyBTNode(3);
	BTNode* n4 = BuyBTNode(4);
	BTNode* n5 = BuyBTNode(5);
	BTNode* n6 = BuyBTNode(6);	
	n1->left = n2;
	n1->right = n4;
	n2->left = n3;
	n4->left = n5;
	n4->right = n6;
	return n1;
}
void qianxu(BTNode* q)
{
	if (q == NULL)
	{
		printf("N ");
		return;
	 }
	printf("%d ", q->val);
	qianxu(q->left);
	qianxu(q->right);
}
void zhongxu(BTNode* q)
{
	if (q == NULL)
	{
		printf("N ");
		return;
	}
	zhongxu(q->left);
	printf("%d ", q->val);
	zhongxu(q->right);
}
void houxu(BTNode* q)
{
	
	if (q == NULL)
	{
		printf("N ");
		return;
	}
	houxu(q->left);
	houxu(q->right);
	printf("%d ", q->val);
	
}
int qiujiedian(BTNode* q)
{
	if (q == NULL)
	{
		return 0;
	}
	return qiujiedian(q->left) + qiujiedian(q->right)+1;
}
//叶子节点
int zqiujiedian(BTNode* q)
{
	if (q == NULL)
	{
		return 0;
	}
	if (zqiujiedian(q->left) == 0 && zqiujiedian(q->right) == 0)
	{
		return 1;
	}
	return qiujiedian(q->left) + qiujiedian(q->right);
}
int gao(BTNode* q)
{
	if (q == NULL)
	{
		return 0;
	}
	int l1 = gao(q->left);
	int l2 = gao(q->right);
	return l1>l2?l1+1:l2+1;
}
int main()
{
	BTNode* arr = CreateTree();
	
	printf("%d ", gao(arr));
	return 0;
}